﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.ServiceModel.Syndication;
using System.Speech.Recognition;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;

namespace DigiMate
{
	public class PauseService : BaseService
	{
		public static string Yes = "Da";
		public static string No = "Niet";
		private System.Threading.Timer timer;
		
		public PauseService()
		{
		}

		protected override Grammar GetGrammar()
		{
			GrammarBuilder grammarBuilder = new GrammarBuilder();
			grammarBuilder.Culture = reco.RecognizerInfo.Culture;
			grammarBuilder.Append(new Choices(SleepService.Yes, SleepService.No));
			return new Grammar(grammarBuilder);
		}

		public override void Run(string text)
		{
			if (inProcess)
				return;

			inProcess = true;
			try
			{
				Speaker.Speak("Хотите чтобы я заткнулась?");

				RecognitionResult res = reco.Recognize(TimeSpan.FromMilliseconds(3000)); // recognize speech
				
				if (res != null && res.Words.Count > 0)
				{
					if (res.Words[0].Text.ToLower() == NewsService.No.ToLower())
					{
						AddLog("No - command received");
						Speaker.Speak("Спасибо, продолжаю работу");
					}
					else if (res.Words[0].Text.ToLower() == NewsService.Yes.ToLower())
					{
						AddLog("Yes - command received");
						Speaker.Speak("Ok, затыкаюсь, досвидания.");
					}

				}
			}
			catch (Exception ex)
			{
				AddLog("There was a problem with rss: " + ex.Message);
			}
			finally
			{
				AddLog("Ended.");

				inProcess = false;
			}
		}
	}
}
